<!DOCTYPE html>
<html lang="en">
<head>
	<meta http-equiv="content-type" content="text/html; charset=UTF-8">
	<meta charset="utf-8">
	<title></title>
	<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1, user-scalable=no">
	<meta name="description" content="">
	<meta name="author" content="">
	<!-- STYLESHEETS --><!--[if lt IE 9]><script src="../../js/flot/excanvas.min.js"></script><script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script><script src="http://css3-mediaqueries-js.googlecode.com/svn/trunk/css3-mediaqueries.js"></script><![endif]-->
	<link rel="stylesheet" type="text/css" href="../../css/cloud-admin.css" >
	<link rel="stylesheet" type="text/css"  href="../../css/themes/default.css" id="skin-switcher" >
	<link rel="stylesheet" type="text/css"  href="../../css/responsive.css" >
	
	<link href="../../font-awesome/css/font-awesome.min.css" rel="stylesheet">
	
	<!-- SELECT2 -->
	<link rel="stylesheet" type="text/css" href="../../js/select2/select2.min.css" />
	<!-- UNIFORM -->
	<link rel="stylesheet" type="text/css" href="../../js/uniform/css/uniform.default.min.css" />
	<!-- datatable -->
    <link rel="stylesheet" href="../../js/datatables/datatable.css">

</head>
<body>
	<header class="navbar clearfix" id="header">
	</header>
	
	<!-- PAGE -->
	<section id="page">
				<!-- SIDEBAR -->
				<div id="sidebar" class="sidebar">
					<div class="sidebar-menu nav-collapse">
						
						<!-- SIDEBAR MENU -->
						<ul>							
							
						</ul>
						<!-- /SIDEBAR MENU -->
					</div>

				</div>
				<!-- /SIDEBAR -->
		<div id="main-content">
			<!-- SAMPLE BOX CONFIGURATION MODAL FORM-->
				<div class="modal fade" id="box-config" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
					<div class="modal-dialog">
						<div class="modal-content" style="width:800px">
							<div class="modal-header">
								<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
								<h4 class="modal-title">维护库存</h4>
							</div>
							<div class="modal-body" style="display:inline">
							    <div class="form-group" style="margin-bottom:10px">
							    	<input type="hidden" name="supplierId"/>
									<label class="control-label col-md-2" style="line-height:34px;">所属店铺：</label>
									<div class="col-md-10 supplierName" style="line-height: 34px">
									</div>
								</div>
								<div class="form-group" style="margin-bottom:10px">
									<label class="control-label col-md-2" style="line-height:34px;">商品名称：</label>
									<div class="col-md-10 productName" style="line-height: 34px">
									</div>
								</div>
								
								<div class="form-group divtiezhi houtai" style="margin-bottom:10px;height:60px">
									<label class="control-label col-md-2">库存信息：</label>
									<div class="col-md-10" style="display:inline-flex">
									<table class="table table-bordered">
									<thead><tr><th>SKU编码</th><th>尺码</th><th>库存</th></tr></thead>
									<tbody class="stock"></tbody>
									</table>
									
								    </div>
								</div>
								
							</div>
							<div class="modal-footer">
								<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
								<button type="button" class="btn btn-success bt-save">保存</button>
							</div>
						</div>
					</div>
				</div>
				<!-- /SAMPLE BOX CONFIGURATION MODAL FORM-->
			<div class="container">
				<div class="row">
					<div id="content" class="col-lg-12">
						<!-- PAGE HEADER-->
						<div class="row">
							<div class="col-sm-12">
								<div class="page-header">
									<!-- STYLER -->
									
									<!-- /STYLER -->
									<!-- BREADCRUMBS -->
									<ul class="breadcrumb">
										<li>
											<i class="fa fa-home"></i>
											<a href="../index.html">首页</a>
										</li>
										<li>
											<a href="#">商品管理</a>
										</li>
										<li>商品列表</li>
									</ul>
									<!-- /BREADCRUMBS -->
									
								</div>
							</div>
						</div>
						<!-- /PAGE HEADER -->
						<!-- FORMS QUERY-->
						<div class="row">
							<div class="col-md-12">
								<div class="row">
									<div class="col-md-12">
										<div class="box border primary">
											<div class="box-title">
												<h4><i class="fa fa-bars"></i>查询条件</h4>
											</div>
											<div class="box-body big" style="padding:10px;">												
												<form class="form-horizontal" role="form">
												  <div class="form-group mrg-bt10">
													<label class="col-sm-1 control-label" style="width: auto">商品名称：</label>
													<div class="col-sm-2" style="width: 150px">
													  <input type="text" class="form-control" name="productName" placeholder="输入关键字">
													</div>
													<label class="col-sm-1 control-label" style="width: auto">商品编码：</label>
													<div class="col-sm-2" style="width: 150px">
													  <input type="text" class="form-control" name="productCode" placeholder="输入关键字">
													</div>
													<label class="col-sm-1 control-label" style="width: auto">商品款式：</label>
													<div class="col-sm-2" style="width: 150px">
													<select id="group_select" class="col-md-12 select2-offscreen" tabindex="-1">
															
													</select>		
													</div>
													<label class="col-sm-1 control-label" style="width: auto">库存小于：</label>
													<div class="col-sm-2" style="width: 150px">
													  <input type="text" class="form-control" name="amount" onkeypress='return $.IsNum(event);' onblur='return $.IsNaN(this);' placeholder="输入数字">
													</div>
													 </div>
													   <div class="form-group mrg-bt10">
													   	<label class="col-sm-1 control-label" style="width: auto">所属店铺：</label>
													<div class="col-sm-2">
													  <select id="supplier_select" name="supplierId" style="width: 100%">
																	   
																	  <option value="1">壹果旗舰店</option>
																	  <option value="2">国贸快闪店</option>
																	  </select>
													</div>
													<div class="col-sm-2" style="width: 120px">
													  <input type="checkbox"  name="preDate"><span style='margin-left:10px'>预售</span>
													</div>
													<div class="col-sm-1" >
									       				<a class="btn btn-primary search">查询</a>
													</div>
												  </div>
												 </form>
											</div>
										</div>
									</div>
								</div>		
						    </div>
						</div>
						<!-- /FORMS QUERY -->
						<div class="row" style="height: 30px;">
								<div class="col-md-12">
									<div class="box ">
										<a href="add_stock_white.html"  class="btn btn-success config">
											<i class="fa  fa-plus-square-o"></i> 库存同步设置
										</a>
										
									</div>
								</div>
					    </div>
					    <div class="row">
								<!-- TABLES -->
								<div class="col-md-12">
									<!-- BOX -->
									<div class="box border primary">
										<div class="box-title">
											<h4><i class="fa fa-table"></i>商品数：<span id="total"></span>条</h4>

										</div>
										<div class="box-body">
											<table id="db_stock_list" cellpadding="0" cellspacing="0" border="0" class="datatable table table-striped table-bordered table-hover">
												
											</table>
										</div>
									</div>
									<!-- /BOX -->
								</div>
							</div>
							<!-- /TABLES -->
						
						
						<div class="footer-tools">
							<span class="go-top">
								<i class="fa fa-chevron-up"></i> Top
							</span>
						</div>
					</div><!-- /CONTENT-->
				</div>
			</div>
		</div>
	</section>
	<!--/PAGE -->
	<!-- JAVASCRIPTS -->
	<!-- Placed at the end of the document so the pages load faster -->
	<!-- JQUERY -->
	<script src="../../js/jquery/jquery-2.0.3.min.js"></script>
	<!-- JQUERY UI-->
	<script src="../../js/jquery-ui-1.10.3.custom/js/jquery-ui-1.10.3.custom.min.js"></script>
	<!-- BOOTSTRAP -->
	<script src="../../bootstrap-dist/js/bootstrap.min.js"></script>
	<!-- BLOCK UI -->
	<script type="text/javascript" src="../../js/jQuery-BlockUI/jquery.blockUI.min.js"></script>

	<!-- AUTOSIZE -->
	<script type="text/javascript" src="../../js/autosize/jquery.autosize.min.js"></script>
	<!-- spinner -->
		<script src="../../js/spinner/spin.js"></script>
	<!-- DATA TABLES -->
		<script type="text/javascript" src="../../js/datatables/bootstrap-select.js"></script>
		<script type="text/javascript" src="../../js/datatables/datatable.js"></script>
		<script type="text/javascript" src="../../js/datatables/datatable-bootstrap.js"></script>
		<script type="text/javascript" src="../../js/datatables/datatable-tabletools.js"></script>
		<script type="text/javascript" src="../../js/datatables/fnAddTr.js"></script>

	<!-- INPUT MASK -->
	<script type="text/javascript" src="../../js/bootstrap-inputmask/bootstrap-inputmask.min.js"></script>
    <!--bootbox-->
	<script type="text/javascript" src="../../js/bootbox/bootbox.min.js"></script>
	<!-- SELECT2 -->
	<script type="text/javascript" src="../../js/select2/select2.min.js"></script>
	<!-- UNIFORM -->
	<script type="text/javascript" src="../../js/uniform/jquery.uniform.min.js"></script>
	
	<!-- COOKIE -->
	<script type="text/javascript" src="../../js/jQuery-Cookie/jquery.cookie.min.js"></script>
	<!-- CUSTOM SCRIPT -->
	<script src="../../js/script.js"></script>
	<script src="../../js/common.js"></script>
		<script language="javascript" src="../../js/print/LodopFuncs.js"></script>
		<script>		
		var ProductStock=function(){
	         var  $mainDataTable=null;
	        
	         
	         var searchProductStock=function(){
	              var groupId=$("#group_select").val();	  
	              var productCode=$("input[name=productCode]").val(); 
	              var productName=$("input[name=productName]").val();      
	              var url=App.getContextPath()+"admin/stock/searchStock.do?productName="+productName+"&productCode="+productCode+"&supplierId="+$("#supplier_select").val();
	                  
	                   url+="&isPre="+$("[name=preDate]").prop("checked");
	                  
		              if(groupId!=-1&&groupId!=null)
		                  url+="&groupId="+groupId;
		            if($("[name=amount]").val()!="")
		            	 url+="&amount="+$("[name=amount]").val();
			       if($mainDataTable){
			           $mainDataTable.api().ajax.url(url).load();	   		
		   		       return;	
			        }
		           var dtSetting = $.dataTableSetting({					
							"ajaxSource" :url,
							"serverSide" : true,
							"bFilter" : false,// 去掉搜索框
							"bLengthChange" : true,// 每页显示数量							
							"sScrollX":"100%",
							"sScrollXInner": "100%",
							"iDisplayLength": 25,
							
							"bSort" : false,					
							"aoColumns" : [ {
								"mDataProp" : "productCode",
								"sTitle" : "商品编码",
								"width" : "10%"				
							}, {
								"mDataProp" : "productName",
								"sTitle" : "商品名称",
								"width" : "15%",
								"render":function(data, type, row){
								if(row.productImages[0].isMain==null){
								
								 					
								  return "<div style='display: inline-flex'><div><img width=100 height=100 src="+getProductImage(row.productImages[0].imagePath,"-200*200.jpg")+"></div><div><a href='"+App.getDomain()+"/product/product.html?productId="+row.productId+"' target='_blank'>"+row.productName+"</a><br></div></div>";
								}
								return "";
								}
							}, {						
								"sTitle" : "商品分类",
								"mDataProp" : "categoryName",
								"width" : "10%"								
							}	
							, {		
							    "mDataProp" : "groupName",				
								"sTitle" : "商品款式 ",
								"width" : "10%"									
							}							
							, {			
							   "mDataProp" : "saleStatus",					
								"sTitle" : "状态",
								"width" : "8%",
								"render":function(data, type, row){
								    return row.saleStatus=="OnSale"?"上架":"下架";
								       
								}
									
							}, {
								"mDataProp" : "skuCode",
								"sTitle" : "SKU信息",
								"width" : "35%"	,
								"render":function(data, type, row){
								var str="";
									$.each(row.ygSkus,function(index,item){
										str+="<p >SKU编码："+item.skuCode+" 尺码："+item.sizeName+" 库存："+item.stock.amount+" </p>";
									});
									
									return str;
								}							
							}, {						
								"sTitle" : "操作",
								"width" : "10%",
								"render":function(data, type, row) {
									var price=row.productSalePrice;
									if(row.promotionPrice>0)
										price=row.promotionPrice
									var str="<p class='btn-toolbar' style='margin:0px'>"+
							     	     "<a class='btn btn-success btn-xs bt-edit btn-width' style='width:60px' href='javascript:;' id="+row.id+" productName="+row.productName+"><i class='fa fa-pencil-square-o'></i>编辑</a>";
							     	    str+="</p>";

								 return str;
								}
							}]
						});					
				      $mainDataTable = $("#db_stock_list").dataTable(dtSetting);
	         };
	       var editStock=function(){
	    	   var id=$(this).attr("id");
	    	   var name=$(this).attr("productName");
	    	   var supplierId=$("#supplier_select").val();
	    	   var supplierName=$("#supplier_select option:selected").text();
	    	   $.ajax({
					type: "post",
					url: App.getContextPath()+"admin/stock/getStockByProductId.do?productId="+id+"&supplierId="+supplierId,
					async: true,			
					success: function(result) {
						if(result!=null){ 
							var skus="";
						$.each(result.extra,function(index,item){
							skus+='<tr class="stockInfo" style="height: 24px"><td class="skuCode" >'+item.skuCode+"</td><td>"+item.sizeName+"</td><td><input type='text' class='form-control' maxlength='3' value="+item.stock.amount+" style='width:50px' onkeypress='return $.IsNum(event);' onblur='return $.IsNaN(this);' /></td></tr>";
						})
							
							$("#box-config").find(".stock").empty().append(skus);
						
							$("#box-config").find(".productName").html(name);
							$("#box-config").find(".supplierName").html(supplierName);
							$("#box-config").find("[name=supplierId]").val(supplierId);
							 $("#box-config").modal("show");
							$("#box-config").find(".bt-save").unbind("click").bind("click",function(){
								var list=[];
								$(".stockInfo").each(function(){
			        				 
			        			var stock={};			        				
			        				 stock.skuCode=$(this).find(".skuCode").html();
			        				 var amount=$(this).find("input").val();
			        				 stock.amount=amount==""?0:amount;
			        				 list.push(stock);
				        		  });
								 $.ajax({
										type: "post",
										url: App.getContextPath()+"admin/stock/updateStock.do",
										data: {stocks:JSON.stringify(list),supplierId:supplierId},
										async: true,			
										success: function(result) {
											 $("#box-config").modal("hide");
											 searchProductStock();
												
										}
								 });
							});
							
						}
						
					}
				});
	       }
	       
	       var printSku=function(){
	    	   var productId=$(this).attr("id");
	    	  
	    	   var skuCode=$(this).attr("skuCode");
	    	   var productName=$(this).attr("productName");
	    	   var sizeName=$(this).attr("sizeName");
	    	   var price=$(this).attr("price");
	    	   var url="http://m.yiigoo.com/cart/skucart.html?productId="+productId+"&skuCode="+skuCode;
	    	   var LODOP;
			   LODOP=getLodop(); 
				LODOP.PRINT_INIT("");
				
				LODOP.PRINT_INITA(-3,0,800,600,"");
				LODOP.SET_PRINT_PAGESIZE(2,700,500,"");
				LODOP.ADD_PRINT_IMAGE(17,8,140,45,"<img src='http://m.yiigoo.com/images/logo.png'/>");
				LODOP.SET_PRINT_STYLEA(0,"Stretch",2);
				LODOP.ADD_PRINT_TEXT(25,82,80,20,"壹果");
				LODOP.SET_PRINT_STYLEA(0,"FontName","Noto Sans S Chinese Regular");
				LODOP.SET_PRINT_STYLEA(0,"FontSize",11);
				LODOP.SET_PRINT_STYLEA(0,"Alignment",2);
				LODOP.ADD_PRINT_BARCODE(48,1,194,170,"QRCode",url);
				LODOP.ADD_PRINT_TEXT(198,2,161,40,productName.trim());
				LODOP.SET_PRINT_STYLEA(0,"FontName","Noto Sans S Chinese Regular");
				LODOP.SET_PRINT_STYLEA(0,"FontSize",8);
				LODOP.ADD_PRINT_TEXT(235,0,146,20,sizeName);
				LODOP.SET_PRINT_STYLEA(0,"FontName","Noto Sans S Chinese Regular");
				LODOP.SET_PRINT_STYLEA(0,"FontSize",8);
				LODOP.SET_PRINT_STYLEA(0,"Alignment",2);
				LODOP.ADD_PRINT_TEXT(235,120,44,20,"￥"+price);
				LODOP.SET_PRINT_STYLEA(0,"FontName","Noto Sans S Chinese Regular");
				LODOP.PREVIEW();	
				
				
	    	   
	    	  
	       }
	       
	       var printProduct=function(){
	    	   var productId=$(this).attr("id");	    	
	    	   var productName=$(this).attr("productName");	    	 
	    	   var price=$(this).attr("price");
	    	   var url="http://m.yiigoo.com/product/product.html?productId="+productId+"&sourceCode=kuaishan";
	    	   var LODOP;
					LODOP=getLodop();
					LODOP.PRINT_INITA(-3,0,800,600,"");
					LODOP.SET_PRINT_PAGESIZE(2,700,500,"");
					LODOP.ADD_PRINT_IMAGE(17,8,140,45,"<img src='http://m.yiigoo.com/images/logo.png'/>");
					LODOP.SET_PRINT_STYLEA(0,"Stretch",2);
					LODOP.ADD_PRINT_TEXT(25,82,80,20,"壹果");
					LODOP.SET_PRINT_STYLEA(0,"FontName","Noto Sans S Chinese Regular");
					LODOP.SET_PRINT_STYLEA(0,"FontSize",11);
					LODOP.SET_PRINT_STYLEA(0,"Alignment",2);
					LODOP.ADD_PRINT_BARCODE(48,1,194,170,"QRCode",url);
					LODOP.ADD_PRINT_TEXT(198,0,161,40,productName.trim());
					LODOP.SET_PRINT_STYLEA(0,"FontName","Noto Sans S Chinese Regular");
					LODOP.SET_PRINT_STYLEA(0,"FontSize",8);
	    	 
	    	   LODOP.ADD_PRINT_TEXT(235,1,162,20,"￥"+price);
	    	   LODOP.SET_PRINT_STYLEA(0,"FontName","Noto Sans S Chinese Regular");
	    	   LODOP.SET_PRINT_STYLEA(0,"Alignment",2);
	    	   LODOP.PRINTA();
	       }
	         
	         return {
	         
	         init:function(){
	        	 $("#supplier_select").select2();           
	             $.ajax({
					type: "post",
					url: App.getContextPath()+"admin/group/searchGroupList.do",
					async: true,			
					success: function(result) {
						if(result!=null)
						{ 
										
							var option="<option value=-1>选择款式</option>";
							$.each(result,function(index,item){								
								 option+="<option value='"+item.id+"'>"+item.groupName+"</option>";
							});
							$("#group_select").empty().append(option).select2({placeholder: "选择款式"});
							
						}
						
					}
				});
				 
	          $(".search").click(searchProductStock);	 
	          searchProductStock();
	          $("#db_stock_list").on("click",".bt-edit",editStock);  
	          $("#db_stock_list").on("click",".bt-print-sku",printSku);  
	          $("#db_stock_list").on("click",".bt-print-product",printProduct);  
	          }
		    }
	      }();
	      
	      $(function(){
	      	$("#header").load("../head.html");	      	
	        App.init(); //Initialise plugins and elements	        
	      	ProductStock.init();
	      	
	      });
		</script>
		<!-- /JAVASCRIPTS -->
</body>
</html>